package algocity.view;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import algocity.modelo.ModeloObservable;
import algocity.view.windows.PanelJuego;
import algocity.view.windows.PanelMenuInicial;

public class VentanaPrincipal extends JFrame implements ActionListener{

	private static final long serialVersionUID = -133982114697528815L;
	
	private PanelMenuInicial panelMenuInicial = new PanelMenuInicial(this);;
	ModeloObservable modelo;
	private JComponent componenteActual;
	private int tamanioGrilla;

	public VentanaPrincipal(ModeloObservable modelo, int tamanioGrilla){
		this.modelo = modelo;
		this.tamanioGrilla = tamanioGrilla;
		
		setTitle("Ventana Principal");
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		setJMenuBar(crearMenuBar());
		setContent(panelMenuInicial);

		setSize(1024, 768);
		setLocation(200, 0);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	private JMenuBar crearMenuBar(){
		JMenuBar menuBar = new JMenuBar();
		JMenu fileMenu = new JMenu("Archivo");
		menuBar.add(fileMenu);
		JMenu editMenu = new JMenu("Editar");
		menuBar.add(editMenu);
		fileMenu.add(new JMenuItem("Guardar"));
		fileMenu.add(new JMenuItem("Salir"));
		return menuBar;
	}

	public void setContent(JComponent componente){
		Container contentPane = getContentPane();
		if (componenteActual != null){
			contentPane.remove(componenteActual);
		}
		contentPane.add(componente,BorderLayout.CENTER);
		componenteActual = componente;
		contentPane.doLayout();
		repaint();
		pack();
		validate();
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == panelMenuInicial.botonIniciarPartida) {
			System.out.println("Boton pulsado iniciarPartida");
			setContent(new PanelJuego(tamanioGrilla,modelo));
		} else {
			System.out.println(e.getActionCommand()+" / "+e.getSource());
		}
	}
	
}
